#! /bin/sh
if [ "$1" = "art" ]
then
	make art_test && ./art_test $2
elif [ "$1" = "index" ]
then
	make distributed_index_test && ./distributed_index_test 4096 4800 10 4 $2
elif [ "$1" = "raft" ]
then
	make raft_test
	total=1
	arg=
	if [ $2 -gt 0 ]
	then
		total=$2
	else
		arg=$2
	fi
	if [ $3 -gt 0 ]
	then
		total=$3
	fi
	fail=0
	success=0
	for i in `seq $total`; do
		echo 'Running Test '$i' of '$total''
		./raft_test $arg
		# ./raft_test $arg > $i
		if [ $? -ne 0 ]
		then
			fail=`expr $fail + 1`
			echo 'Test Failed at '$i''
		else
			success=`expr $success + 1`
			# rm $i
		fi
	done
	echo 'Total '$total'  Fail '$fail'  Success '$success''
elif [ "$1" = "blink" ]
then
	if [ "$2" = "queue" ]
	then
		make blinktree_with_queue_test && ./blinktree_with_queue_test 4096 4800 10 4 $3
	elif [ "$2" = "thread" ]
	then
		make blinktree_multi_thread_test && ./blinktree_multi_thread_test 4096 4800 10 4 $3
		else
			echo "wrong argument :("
	fi
elif [ "$1" = "network" ]
then
	if [ "$2" = "client" ]
	then
		make client_test && ./client_test
	elif [ "$2" = "server" ]
	then
		make server_test && ./server_test
		else
			echo "wrong argument :("
	fi
elif [ "$1" = "rpc" ]
then
	if [ "$2" = "client" ]
	then
		make rpc_client_test && ./rpc_client_test $3
	elif [ "$2" = "server" ]
	then
		make rpc_server_test && ./rpc_server_test
	else
		echo "wrong argument :("
	fi
else
	echo "wrong argument :("
fi
